/***********************************************************************************
Copy right:	    Coffee Tech.
Author:         wusong
Date:           2021年12月3日
Description:    和m0通信的相关头文件
***********************************************************************************/

#ifndef __M0_UART_H_
#define __M0_UART_H_



/**
 * @brief 数据点的名称,这里的想法是整个系统最好是统一
 * 
 */
#define NAME_STR_TEMPERATURE "temperature"
#define NAME_STR_HUMIDITY "humidity"
#define NAME_STR_ILL "ill"
#define NAME_STR_LIGHT "light"
#define NAME_STR_ALARM "alarm"
#define NAME_STR_FAN "fan"
#define UART_MAGIC_HEADER "st:"

#define MAX_DATA_NODE (0xFF - 1)


//仓库编号
#define STORE1  0x40
#define STORE2  0x80
#define STORE3  0xc0

#define STORE_NO STORE2

//设备编号
#define FAN  0x00
#define BEEP 0x10
#define LED  0x20


enum MO_CMD{
    // 风扇的命令
    FAN_OFF = STORE_NO|FAN|0x00,
    FAN_1 = STORE_NO|FAN|0x01,
    FAN_2 = STORE_NO|FAN|0x02,
    FAN_3 = STORE_NO|FAN|0x03,

    // 蜂鸣器的命令
    BEEP_OFF = STORE_NO|BEEP|0x00,
    BEEP_ON = STORE_NO|BEEP|0x01,
    BEEP_ALRRM_OFF = STORE_NO|BEEP|0x02,
    BEEP_ALRRM_ON = STORE_NO|BEEP|0x03,

    //灯的命令
    LED_OFF = STORE_NO|LED|0x00,
    LED_ON = STORE_NO|LED|0x01,
};



#define NODE_KEY_FAN	6
#define NODE_KEY_ALARM	5
#define NODE_KEY_LIGHT	4




extern char uart_r_buf[];
extern int m0_fd;
extern int header_total;

void m0_init(void);
void m0_uart_get_header(char *buf);
int m0_read_with_len_block(char *buf, int len);
void m0_uart_reopen(void);
int m0_set_cmd(int key, int val);


#endif //__M0_UART_H_
